/*
 * JSF Toolkit Component Framework
 * Copyright (C) 2007 Noah Sloan <iamnoah A-T gmail D0T com>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 */
package com.jsftoolkit.gen.info;

import com.jsftoolkit.utils.Utils;

/**
 * Base class for subcomponents of {@link ComponentInfo} that need a reference
 * back to the owning instance.
 * 
 * @author noah
 */
public abstract class ChildInfo extends ClassInfo {
	private ComponentInfo component;

	/**
	 * Initializes nothing.
	 */
	public ChildInfo() {
		super();
	}

	/**
	 * Initializes the parent component.
	 * 
	 * @param component
	 */
	public ChildInfo(ComponentInfo component) {
		this();
		this.component = component;
	}

	/**
	 * Passes through to
	 * {@link ClassInfo#ClassInfo(String, String, boolean, Class[])}
	 * 
	 * @param _package
	 * @param className
	 * @param _abstract
	 * @param interfaces
	 */
	public ChildInfo(String _package, String className, boolean _abstract,
			Class<?>... interfaces) {
		super(_package, className, _abstract, interfaces);
	}

	/**
	 * @return the set package name, unless it is null, in which case the parent
	 *         package is returned (if it is non-null).
	 */
	@Override
	public String getPackage() {
		return Utils.getValue(super.getPackage(), component == null ? null
				: component.getPackage());
	}

	/**
	 * 
	 * @return the component we are the child of
	 */
	public ComponentInfo getComponent() {
		return component;
	}

	public void setComponent(ComponentInfo component) {
		this.component = component;
	}

}
